/* $Id: PageHome.java 138 2011-09-01 17:51:37Z altdotua@gmail.com $ */

package alt.djudge.frontend.client.ui.contest;

import alt.djudge.frontend.client.ui.AbstractLayout;
import alt.djudge.frontend.client.ui.AsyncCallbackSucc;
import alt.djudge.frontend.client.ui.ContentPage;
import alt.djudge.frontend.shared.dto.contest.ContestInfoDTO;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;


public class PageHome extends Composite implements ContentPage
{
	interface MyUiBinder extends UiBinder<VerticalPanel, PageHome> {}

	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

	@UiField
	VerticalPanel panel;
	
	@UiField
	Label lblTitle;
	
	@UiField
	Label lblName;
	
	@UiField
	Label lblStartTime;
	
	@UiField
	Label lblFinishTime;
	
	ContestInfoDTO contestInfo;
	
	public PageHome()
	{
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	public void showData(ContestInfoDTO contest)
	{
		this.contestInfo = contest;
		
		lblTitle.setText("Contest " + contest.getName() + " info");
		
		lblName.setText(contest.getName());
		lblStartTime.setText(contest.getStartTime().toString());
		lblFinishTime.setText(contest.getFinishTime().toString());
	}
	
	public void loadData()
	{
		AsyncCallback<ContestInfoDTO> callback = AbstractLayout.getLayout().getAsyncCallback(new AsyncCallbackSucc<ContestInfoDTO>()
		{

			@Override
			public void onSuccess(ContestInfoDTO result)
			{
				showData(result);
			}
			
		});
		Layout.contestService.getContestInfo(Layout.getLayout().getContestId(), callback);
	}

	@Override
	public void dispatch(String token)
	{
		loadData();
	}

	@Override
	public String getHistoryTokenPrefix()
	{
		return "home";
	}
}

